package com.berchen.passdb.service;

import com.berchen.busidb.dao.BusidbMapper;
import com.berchen.common.busidb.model.BillVo;
import com.berchen.common.busidb.service.BusidbService;
import com.berchen.common.passdb.model.PassVo;
import com.berchen.common.passdb.service.PassdbService;
import com.berchen.passdb.dao.PassdbMapper;
import com.berchen.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Transactional(transactionManager = "passTx",propagation = Propagation.REQUIRED)
@Service
public class PassdbServiceImpl implements PassdbService {

    @Autowired
    private PassdbMapper mapper;

    @Override
    public boolean addPass(PassVo vo) {


        // MD5 进行加密 但是 不可逆 所以程序不能找到原始值
//        vo.setPassMd5(MD5Util.md5(vo.getPassword())+"a1a"+MD5Util.md5(UUID.randomUUID().toString()));
        //

        vo.setPassMd5(MD5Util.convertMD5(vo.getPassword())+"a1a"+MD5Util.convertMD5(UUID.randomUUID().toString()));

        // 根据账号和应用查询是否存在该账号
        PassVo passVo=mapper.getPass(vo);
        if(passVo!=null) {
            mapper.addPass(vo);
            return true;
        }
        return false;
    }

    @Override
    public PassVo getPass(PassVo vo) {
        return mapper.getPass(vo);
    }

    @Override
    public List<PassVo> getPasss(PassVo vo) {
        return mapper.getPasss(vo);
    }
}
